<template>
  <div>
    <el-form :model="queryParams" ref="queryForm" size="mini" v-show="showSearch" label-width="68px">
      <el-row :gutter="20">
        <el-col :span="4">
          <el-form-item label="项目区域" prop="projectRegion">
            <el-select v-model="queryParams.projectRegion" placeholder="请选择" clearable
              @keyup.enter.native="handleQuery">
              <el-option v-for="dict in dict.type.cld_project_region" :key="dict.value" :label="dict.label"
                :value="parseInt(dict.value)"></el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="4">
          <el-form-item label="项目名称" prop="projectName">
            <el-input v-model="queryParams.projectName" placeholder="请输入" clearable @keyup.enter.native="handleQuery" />
          </el-form-item>
        </el-col>
        <!-- <el-col :span="4">
          <el-form-item label="打卡日期">
            <el-date-picker v-model="dateRange" value-format="yyyy-MM-dd" type="daterange" range-separator="-"
              start-placeholder="开始日期" end-placeholder="结束日期"></el-date-picker>
          </el-form-item>
        </el-col> -->
        <el-col :span="4">
          <el-form-item label-width="10px">
            <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
            <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <el-table v-loading="loading" :data="attendanceList" border>
      <el-table-column label="项目区域" align="center" prop="projectRegion">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.cld_project_region" :value="scope.row.projectRegion" />
        </template>
      </el-table-column>
      <el-table-column label="项目名称" align="center" prop="projectName"/>
      <el-table-column label="项目状态" align="center" prop="contractStatus" >
        <template slot-scope="scope">
          <el-tag v-if="scope.row.contractStatus == 1" type="success">履约中</el-tag>
          <el-tag v-if="scope.row.contractStatus == 2" type="danger">已到期</el-tag>
          <el-tag v-if="scope.row.contractStatus == 3" type="info">已终止</el-tag>
        </template>
      </el-table-column>
      <el-table-column label="在岗人数" align="center" prop="theJobCount" />
      <el-table-column label="缺岗人数" align="center" prop="vacanciesCount" />
      <el-table-column label="缺岗率" align="center">
        <template slot-scope="scope">
          <span>{{ calculatePercentage(scope.row.vacanciesCount, scope.row.vacanciesCount + scope.row.theJobCount) }}</span>
        </template>
      </el-table-column>
      <el-table-column label="应出勤人数" align="center" prop="attCount" />
      <el-table-column label="当天出勤人数" align="center" prop="attendanceCount" />
      <el-table-column label="当天缺勤人数" align="center"  >
        <template slot-scope="scope">
          <span>{{ scope.row.attCount - scope.row.attendanceCount }}</span>
        </template>
      </el-table-column>
      <el-table-column label="出勤率" align="center">
        <template slot-scope="scope">
          <span>{{ calculatePercentage(scope.row.attendanceCount, scope.row.attCount) }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button size="mini" type="text" @click="handleView(scope.row)"
            v-hasPermi="['cld:attendance:query']">查看考勤</el-button>

        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
      @pagination="getList" />
  </div>
</template>

<script>
import { projectClassificationList } from "@/api/cld/attendance";

export default {
  name: "Attendance",
  dicts: ['cld_project_region'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 考勤打卡表格数据
      attendanceList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        projectRegion: null,
        projectName: null
      },
      dateRange: [],
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询考勤打卡列表 */
    getList() {
      this.loading = true;
      projectClassificationList(this.addDateRange(this.queryParams, this.dateRange)).then(response => {
        this.attendanceList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.dateRange = [];
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 查看考勤
    handleView(row) {
      this.$router.push("/attendance/viewAttendance/view/" + row.projectId);
    }
  }
};
</script>
<style scoped>
.el-range-editor.el-input__inner {
  width: 100%;
}

.el-select {
  width: 100%;
}
</style>
